package com.ssy.lingxi.platform.template.service.constant;

import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;

/**
 * 活动页状态 - enum
 * @author fhj
 * @date 2021/08/06
 * @version 2.0.0
 */
public enum ActivityPageStatusEnum {

    WAIT_OPEN_LINE(1, "待上线"),
    ALREADY_OPEN_LINE(2, "已上线"),
    START(3, "进行中"),
    OFF_LINE(4, "已下线"),
    END(5, "已结束"),
    INVALID_STATE(6, "无效状态")
    ;

    private final Integer code;
    private final String message;

    ActivityPageStatusEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 根据code获取message
     * */
    public static String getMessage(Integer code) {
        String key = ActivityPageStatusEnum.class.getSimpleName().concat(".");
        ActivityPageStatusEnum activityPageStatusEnum = Arrays.stream(ActivityPageStatusEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        return activityPageStatusEnum != null ?LanguageHolder.getName(key.concat(String.valueOf(code))): LanguageHolder.getName(key.concat(String.valueOf(ActivityPageStatusEnum.INVALID_STATE.getCode())));
    }

    /**
     * 判断是否能修改
     * */
    public static Boolean isUpdate(Integer code) {
        return code.equals(WAIT_OPEN_LINE.code) || code.equals(OFF_LINE.code);
    }

    /**
     * 判断是否能删除
     * */
    public static Boolean isDelete(Integer code) {
        return code.equals(WAIT_OPEN_LINE.code);
    }

    /**
     * 判断是否能上线
     * */
    public static Boolean isOpenLine(Integer code) {
        return code.equals(WAIT_OPEN_LINE.code) || code.equals(OFF_LINE.code);
    }

    /**
     * 判断是否能下线
     * */
    public static Boolean isOffLine(Integer code) {
        return code.equals(ALREADY_OPEN_LINE.code) || code.equals(START.code);
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return LanguageHolder.getName(this.getClass(),this.code);
    }
}
